// index.js
var util = require('../../utils/util.js');
const api = require('../../config/api.js');
Page({
    data: {
        windowHeight:0,//屏幕高度
        statusBarHeight: 0,//状态栏
        navBarHeight: 0,//导航栏
        statusBarHeightmargintop: 0,//胶囊上边距
        safeHeight: 0,//安全区域，内容区域 + 导航栏
        bottomSafeHeight: 0,

        //元素宽高
        fenquHeight:0,//分区高度
        tunavliWidth:0,//图副本li宽度
        poptunavliWidth:0,//弹窗图副本li宽度
        listHeight:0,//滚动区域高度

        //弹窗
        showpopjuese: false ,
        showpoptuan: false,
        showpopguize: false,
        mapList: []
      },
      onShow: function () {
        let token = wx.getStorageSync('token');
        this.getMap();
    
      },
      //获取元素宽高
      getRect: function () {
        var _this = this;
        wx.createSelectorQuery().selectAll('.fenqu,.in_tu_nav').boundingClientRect().exec(function(res){
          _this.setData({
            fenquHeight: res[0][0].height,
            tunavliWidth:res[0][1].width/3-10/3*2,//10为margin-left值
          });
        });
        setTimeout(() => {
            const windowInfo = wx.getWindowInfo();
            wx.createSelectorQuery().selectAll('.header,.index_nav,.in_tu_nav,.foot_tabbar').boundingClientRect().exec(function(res){
                _this.setData({
                    listHeight: windowInfo.screenHeight-res[0][0].height-res[0][1].height-res[0][2].height-res[0][3].height-20,
                });
              });
          }, 300);
        
      },
      onLoad() {
        // 获取系统顶部数值
        const windowInfo = wx.getWindowInfo();
        const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
        let windowHeight = windowInfo.screenHeight;
        let statusBarHeight = windowInfo.statusBarHeight;
        let navBarHeight =
          menuButtonInfo.height + (menuButtonInfo.top - statusBarHeight) * 2;
        let statusBarHeightmargintop =
          menuButtonInfo.top - statusBarHeight;
        let safeHeight = windowInfo.safeArea.height;
        let bottomSafeHeight =
          windowInfo.screenHeight - windowInfo.safeArea.height - statusBarHeight;
        this.setData({
          windowHeight,
          statusBarHeight,
          navBarHeight,
          statusBarHeightmargintop,
          safeHeight,
          bottomSafeHeight,
        });
        
        //调用 计算高度 的方法
        this.getRect();
        
      },
    // 弹窗，角色
    showpopjuese() {
        this.setData({ showpopjuese: true });
    },
    hidepopjuese() {
        this.setData({ showpopjuese: false });
    },
    //弹窗，组团
    showpoptuan() {
        this.setData({ showpoptuan: true });
        //获取宽高
        var _this = this;
        wx.createSelectorQuery().selectAll('.pop_tu_nav').boundingClientRect().exec(function(res){
          _this.setData({
            poptunavliWidth:res[0][0].width/3-6/3*2,//6为margin-left值
          });
        });
    },
    hidepoptuan() {
        this.setData({ showpoptuan: false });
    },
    // 弹窗，规则
    showpopguize() {
        this.setData({ showpopguize: true });
    },
    hidepopguize() {
        this.setData({ showpopguize: false });
    },
    getMap(){
      util.request(api.IndexMapList, {}, 'GET').then(res => {
        console.info("res",res)
        if (res.code == 200) {
          this.setData({
            mapList: res.data
          })
        } else {
          util.showErrorToast(res.msg)
        
        }
      })
    }


})
